﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Caching;

namespace SampleKeyValueDemo
{
    public class AppCacheStore<T> : IKeyValueDataStore<T>
    {
        private Cache MyCache { get { return HttpRuntime.Cache; } }
        private string Prefix { get { return typeof(T).FullName; } }
        
        

        public void Set(string key, T val)
        {
            key = Prefix + key;
            this.MyCache.Add(key, val, null, DateTime.Now.AddDays(1), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);

        }

        public T Get(string key)
        {
            key = Prefix + key;
            return (T)this.MyCache[key];
        }

        public void Remove(string key)
        {
            key = Prefix + key;
            this.MyCache.Remove(key);
        }
    }
}